<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"littlefxc.github.io","root":"/","images":"/images","scheme":"Mist","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta name="description" content="引言工欲善其事，必先利其器。 因为只有一台电脑，只能搭建伪集群来学习了，但是，本身又是个偷懒的人，启动伪集群 RocketMQ 的命令有点多，不想敲那么多的命令，顺便将搭建 RocketMQ 集群的部署方式记录一下。 RocketMQ 的部署方式有3种：  2m-noslave：多 Master 模式，无 Slave。[双主模式] 优点：配置简单，性能最高 缺点：可能会有少量消息丢失（配置相关），">
<meta property="og:type" content="article">
<meta property="og:title" content="自定义脚本启动搭建的RocketMQ伪集群">
<meta property="og:url" content="http://littlefxc.github.io/2022/04/02/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E8%87%AA%E5%AE%9A%E4%B9%89%E8%84%9A%E6%9C%AC%E5%90%AF%E5%8A%A8%E6%90%AD%E5%BB%BA%E7%9A%84RocketMQ%E4%BC%AA%E9%9B%86%E7%BE%A4/index.html">
<meta property="og:site_name" content="一年春又来">
<meta property="og:description" content="引言工欲善其事，必先利其器。 因为只有一台电脑，只能搭建伪集群来学习了，但是，本身又是个偷懒的人，启动伪集群 RocketMQ 的命令有点多，不想敲那么多的命令，顺便将搭建 RocketMQ 集群的部署方式记录一下。 RocketMQ 的部署方式有3种：  2m-noslave：多 Master 模式，无 Slave。[双主模式] 优点：配置简单，性能最高 缺点：可能会有少量消息丢失（配置相关），">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://littlefxc.github.io/Users/fengxuechao/Library/Application%20Support/typora-user-images/image-20220402143803612.png">
<meta property="og:image" content="http://littlefxc.github.io/Users/fengxuechao/Library/Application%20Support/typora-user-images/image-20220402143514440.png">
<meta property="og:image" content="http://littlefxc.github.io/Users/fengxuechao/Library/Application%20Support/typora-user-images/image-20220402163857315.png">
<meta property="article:published_time" content="2022-04-01T18:47:11.000Z">
<meta property="article:modified_time" content="2022-05-10T01:27:12.539Z">
<meta property="article:author" content="一年春又来">
<meta property="article:tag" content="rocketmq">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://littlefxc.github.io/Users/fengxuechao/Library/Application%20Support/typora-user-images/image-20220402143803612.png">


<link rel="canonical" href="http://littlefxc.github.io/2022/04/02/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E8%87%AA%E5%AE%9A%E4%B9%89%E8%84%9A%E6%9C%AC%E5%90%AF%E5%8A%A8%E6%90%AD%E5%BB%BA%E7%9A%84RocketMQ%E4%BC%AA%E9%9B%86%E7%BE%A4/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>自定义脚本启动搭建的RocketMQ伪集群 | 一年春又来</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="一年春又来" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">一年春又来</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="home                          //首页 fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="archive          //归档 fa-fw"></i>归档</a></li>
        <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="th           //分类 fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="tags                     //标签 fa-fw"></i>标签</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%95%E8%A8%80"><span class="nav-text">引言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AB%AF%E5%8F%A3%E8%A7%84%E5%88%92"><span class="nav-text">端口规划</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%8B%E8%BD%BD"><span class="nav-text">下载</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-text">配置文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9-JVM-%E5%90%AF%E5%8A%A8%E8%B5%84%E6%BA%90%E8%A6%81%E7%B4%A0"><span class="nav-text">修改 JVM 启动资源要素</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%80%E9%94%AE%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC"><span class="nav-text">一键启动脚本</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%BF%90%E8%A1%8C%E6%83%85%E5%86%B5"><span class="nav-text">运行情况</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E6%A1%A3"><span class="nav-text">参考文档</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">一年春又来</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">234</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">38</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">125</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2022/04/02/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E8%87%AA%E5%AE%9A%E4%B9%89%E8%84%9A%E6%9C%AC%E5%90%AF%E5%8A%A8%E6%90%AD%E5%BB%BA%E7%9A%84RocketMQ%E4%BC%AA%E9%9B%86%E7%BE%A4/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          自定义脚本启动搭建的RocketMQ伪集群
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-04-02 02:47:11" itemprop="dateCreated datePublished" datetime="2022-04-02T02:47:11+08:00">2022-04-02</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:27:12" itemprop="dateModified" datetime="2022-05-10T09:27:12+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">分布式系统</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="引言"><a href="#引言" class="headerlink" title="引言"></a>引言</h2><p>工欲善其事，必先利其器。</p>
<p>因为只有一台电脑，只能搭建伪集群来学习了，但是，本身又是个偷懒的人，启动伪集群 RocketMQ 的命令有点多，不想敲那么多的命令，顺便将搭建 RocketMQ 集群的部署方式记录一下。</p>
<p>RocketMQ 的部署方式有3种：</p>
<ul>
<li>2m-noslave：多 Master 模式，无 Slave。[双主模式]<ul>
<li>优点：配置简单，性能最高</li>
<li>缺点：可能会有少量消息丢失（配置相关），单台机器重启或宕机期间，该机器下未被消费的消息在机器恢复前不可订阅，影响消息实时性</li>
</ul>
</li>
<li>2m-2s-sync：多 Master 多 Slave 模式，同步双写。[双主双从+同步模式]<ul>
<li>优点：服务可用性与数据可用性非常高</li>
<li>缺点：性能比异步集群略低</li>
</ul>
</li>
<li>2m-2s-async：多 Master 多 Slave 模式，异步复制。[双主双从+异步模式]<ul>
<li>优点：性能同多Master几乎一样，实时性高，主备间切换对应用透明，不需人工干预</li>
<li>缺点：Master宕机或磁盘损坏时会有少量消息丢失</li>
</ul>
</li>
</ul>
<p>本文主要记录一下同步双写模式的搭建步骤和一键启动脚本。</p>
<h2 id="端口规划"><a href="#端口规划" class="headerlink" title="端口规划"></a>端口规划</h2><p>首先，因为只有一台电脑，端口要进行规划，以避免端口占用的问题。</p>
<p>采用的方案就是“双主双从+同步模式”。</p>
<table>
<thead>
<tr>
<th>名称</th>
<th>端口</th>
</tr>
</thead>
<tbody><tr>
<td>namesrv1</td>
<td>9876</td>
</tr>
<tr>
<td>Namesrv2</td>
<td>9877</td>
</tr>
<tr>
<td>brokera-master</td>
<td>10910</td>
</tr>
<tr>
<td>brokera-slave</td>
<td>10920</td>
</tr>
<tr>
<td>brokerb-master</td>
<td>10930</td>
</tr>
<tr>
<td>brokerb-slave</td>
<td>10940</td>
</tr>
</tbody></table>
<h2 id="下载"><a href="#下载" class="headerlink" title="下载"></a>下载</h2><p><a target="_blank" rel="noopener" href="https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.9.3/rocketmq-all-4.9.3-bin-release.zip">https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.9.3/rocketmq-all-4.9.3-bin-release.zip</a></p>
<h2 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim rocketmq/conf/2m-2s-sync/broker-a.properties</span><br></pre></td></tr></table></figure>

<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 集群名字</span></span><br><span class="line"><span class="string">brokerClusterName=DefaultCluster</span></span><br><span class="line"><span class="comment"># broker 名字，可重复，master 的名字和 slave 的名字保持一致</span></span><br><span class="line"><span class="string">brokerName=broker-a</span></span><br><span class="line"><span class="comment"># 0 表示 master, &gt;0 表示 slave </span></span><br><span class="line"><span class="string">brokerId=0</span></span><br><span class="line"><span class="comment"># 删除文件时间点，默认凌晨 4点</span></span><br><span class="line"><span class="string">deleteWhen=04</span></span><br><span class="line"><span class="comment"># 文件保留时间，默认 48 小时</span></span><br><span class="line"><span class="string">fileReservedTime=48</span></span><br><span class="line"><span class="comment"># Broker 的角色</span></span><br><span class="line"><span class="string">brokerRole=SYNC_MASTER</span></span><br><span class="line"><span class="comment"># 刷盘方式</span></span><br><span class="line"><span class="string">flushDiskType=ASYNC_FLUSH</span></span><br><span class="line"><span class="comment"># Broker 对外服务的监听端口, 注意需改端口, 并且要和默认的10911相差5以上</span></span><br><span class="line"><span class="string">listenPort=10910</span></span><br><span class="line"><span class="comment"># 是否允许 Broker 自动创建Topic，建议线下开启，线上关闭</span></span><br><span class="line"><span class="string">autoCreateTopicEnable=true</span></span><br><span class="line"><span class="comment"># 是否允许 Broker 自动创建订阅组，建议线下开启，线上关闭</span></span><br><span class="line"><span class="string">autoCreateSubscriptionGroup=true</span></span><br><span class="line"><span class="comment"># nameServer地址，分号分割</span></span><br><span class="line"><span class="string">namesrvAddr=localhost:9876;localhost:9877</span></span><br><span class="line"><span class="comment"># 存储路径</span></span><br><span class="line"><span class="string">storePathRootDir=/usr/local/var/lib/rocketmq/broker-a</span></span><br><span class="line"><span class="comment"># commitLog 存储路径</span></span><br><span class="line"><span class="string">storePathCommitLog=/usr/local/var/lib/rocketmq/broker-a/commitlog</span></span><br><span class="line"><span class="comment"># 消费队列存储路径存储路径</span></span><br><span class="line"><span class="string">storePathConsumeQueue=/usr/local/var/lib/rocketmq/broker-a/consumequeue</span></span><br><span class="line"><span class="comment"># 消息索引存储路径</span></span><br><span class="line"><span class="string">storePathIndex=/usr/local/var/lib/rocketmq/broker-a/index</span></span><br><span class="line"><span class="comment"># checkpoint 文件存储路径</span></span><br><span class="line"><span class="string">storeCheckpoint=/usr/local/var/lib/rocketmq/broker-a/checkpoint</span></span><br><span class="line"><span class="comment"># abort 文件存储路径</span></span><br><span class="line"><span class="string">abortFile=/usr/local/var/lib/rocketmq/broker-a/about</span></span><br></pre></td></tr></table></figure>

<p>其它节点的配置文件类似只需修改一下 <code>brokerId</code>、 <code>brokerName</code>、<code>listenPort</code>、<code>brokerRole</code>和<code>store*</code>这些参数即可。</p>
<h2 id="修改-JVM-启动资源要素"><a href="#修改-JVM-启动资源要素" class="headerlink" title="修改 JVM 启动资源要素"></a>修改 JVM 启动资源要素</h2><p>还是因为本身只有一台机器，资源有限的原因。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim rocketmq-4.9.3/bin/runbroker.sh</span><br></pre></td></tr></table></figure>

<p><img src="/Users/fengxuechao/Library/Application%20Support/typora-user-images/image-20220402143803612.png" alt="image-20220402143803612"></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim rocketmq-4.9.3/bin/runserver.sh</span><br></pre></td></tr></table></figure>

<p><img src="/Users/fengxuechao/Library/Application%20Support/typora-user-images/image-20220402143514440.png" alt="image-20220402143514440"></p>
<h2 id="一键启动脚本"><a href="#一键启动脚本" class="headerlink" title="一键启动脚本"></a>一键启动脚本</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"><span class="built_in">export</span> JAVA_HOME=<span class="string">&quot;/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home&quot;</span></span><br><span class="line"><span class="built_in">export</span> ROCKETMQ_HOME=<span class="string">&quot;/usr/local/rocketmq-4.9.3&quot;</span></span><br><span class="line"><span class="built_in">export</span> ROCKETMQ_LOG_DIR=<span class="string">&quot;/usr/local/var/log/rocketmq&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> [ <span class="variable">$1</span> == <span class="string">&quot;startall&quot;</span> ] <span class="keyword">then</span></span><br><span class="line">    <span class="comment"># 启动 namesrv1</span></span><br><span class="line">    nohup sh <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqnamesrv -c <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/conf/2m-2s-sync/namesrv-1.properties &gt; <span class="variable">$&#123;ROCKETMQ_LOG_DIR&#125;</span>/mqnamesrv1.log 2&gt;&amp;1 &amp;</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 启动 namesrv2</span></span><br><span class="line">    nohup sh <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqnamesrv -c <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/conf/2m-2s-sync/namesrv-2.properties &gt; <span class="variable">$&#123;ROCKETMQ_LOG_DIR&#125;</span>/mqnamesrv2.log 2&gt;&amp;1 &amp;</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 启动 broker-a</span></span><br><span class="line">    nohup sh <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqbroker -c <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/conf/2m-2s-sync/broker-a.properties &gt; <span class="variable">$&#123;ROCKETMQ_LOG_DIR&#125;</span>/broker-a.log 2&gt;&amp;1 &amp;</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 启动 broker-a-s</span></span><br><span class="line">    nohup sh <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqbroker -c <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/conf/2m-2s-sync/broker-a-s.properties &gt; <span class="variable">$&#123;ROCKETMQ_LOG_DIR&#125;</span>/broker-a-s.log 2&gt;&amp;1 &amp;</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 启动 broker-b</span></span><br><span class="line">    nohup sh <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqbroker -c <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/conf/2m-2s-sync/broker-b.properties &gt; <span class="variable">$&#123;ROCKETMQ_LOG_DIR&#125;</span>/broker-b.log 2&gt;&amp;1 &amp;</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 启动 broker-b-s</span></span><br><span class="line">    nohup sh <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqbroker -c <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/conf/2m-2s-sync/broker-b-s.properties &gt; <span class="variable">$&#123;ROCKETMQ_LOG_DIR&#125;</span>/broker-b-s.log 2&gt;&amp;1 &amp;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">export</span> NAMESRV_ADDR=localhost:9876,localhost:9877</span><br><span class="line"></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">&quot;rocketmq 集群启动成功!&quot;</span></span><br><span class="line"><span class="keyword">elif</span>[ <span class="variable">$1</span> == <span class="string">&quot;start&quot;</span> ] <span class="keyword">then</span> </span><br><span class="line">    nohup <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqnamesrv &amp;</span><br><span class="line">    nohup <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqbroker -n localhost:9876 &amp;</span><br><span class="line">    <span class="built_in">export</span> NAMESRV_ADDR=localhost:9876</span><br><span class="line">    <span class="built_in">echo</span> <span class="string">&quot;rocketmq 单机启动成功!&quot;</span></span><br><span class="line"><span class="keyword">elif</span> [ <span class="variable">$1</span> == <span class="string">&quot;stop&quot;</span> ] <span class="keyword">then</span> </span><br><span class="line">    <span class="comment"># 先关闭 broker</span></span><br><span class="line">    sh <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqshutdown broker</span><br><span class="line">    <span class="comment"># 再关闭 namesrv</span></span><br><span class="line">    sh <span class="variable">$&#123;ROCKETMQ_HOME&#125;</span>/bin/mqshutdown namesrv</span><br><span class="line">    <span class="built_in">echo</span> <span class="string">&quot;rocketmq 关闭成功!&quot;</span></span><br><span class="line"><span class="keyword">else</span> </span><br><span class="line">    <span class="built_in">echo</span> <span class="string">&quot;rockermq_service.sh (startall|start|stop)&quot;</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>

<h2 id="运行情况"><a href="#运行情况" class="headerlink" title="运行情况"></a>运行情况</h2><p><img src="/Users/fengxuechao/Library/Application%20Support/typora-user-images/image-20220402163857315.png" alt="image-20220402163857315"></p>
<h2 id="参考文档"><a href="#参考文档" class="headerlink" title="参考文档"></a>参考文档</h2><p><a target="_blank" rel="noopener" href="https://github.com/apache/rocketmq/blob/master/docs/cn/operation.md">官方中文部署文档</a></p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/rocketmq/" rel="tag"># rocketmq</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2022/04/01/docs/JVM/JVM-%E6%97%A5%E5%BF%97/" rel="prev" title="JVM 日志">
                  <i class="fa fa-chevron-left"></i> JVM 日志
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2022/04/07/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/RocketMQ%E4%BA%8B%E5%8A%A1%E6%B6%88%E6%81%AF%E7%A4%BA%E4%BE%8B/" rel="next" title="RocketMQ事务消息示例">
                  RocketMQ事务消息示例 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">一年春又来</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  
<script src="/js/local-search.js"></script>






  





</body>
</html>
